package cn.wolfcode.crm.service.impl;

import cn.wolfcode.crm.domain.DataDictionaryItem;
import cn.wolfcode.crm.mapper.DataDictionaryItemMapper;
import cn.wolfcode.crm.query.QueryObject;
import cn.wolfcode.crm.service.IDataDictionaryItemService;
import cn.wolfcode.crm.util.PageResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class DataDictionaryItemServiceImpl implements IDataDictionaryItemService {

    @Autowired
    private DataDictionaryItemMapper mapper;

    public List<DataDictionaryItem> getItemByDictionarySn(String sn) {
        return mapper.getItemByDictionarySn(sn);
    }

    public void save(DataDictionaryItem entity) {
        mapper.insert(entity);
    }

    public void delete(Long id) {
        mapper.deleteByPrimaryKey(id);
    }

    public void update(DataDictionaryItem entity) {
        mapper.updateByPrimaryKey(entity);
    }

    public DataDictionaryItem get(Long id) {
        return mapper.selectByPrimaryKey(id
        );
    }

    public List<DataDictionaryItem> list() {
        return mapper.selectAll();
    }

    public PageResult query(QueryObject qo) {
        PageResult pr = new PageResult();
        //查总条数
        int total = mapper.queryForCount();
        if (total == 0) {
            return pr;
        }
        //查分页数量
        List<DataDictionaryItem> rows = mapper.queryForList(qo);
        pr.setRows(rows);
        pr.setTotal(total);
        return pr;
    }
}
